<template>
    <div class="goods-list">
        <div class="goods-item" v-for="item in goodsLists" :key="item.img_src" @click="goDetail(item.id)">
            <img :src="item.img_src" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.price_now}}</span>
                    <span class="old">￥{{item.price_old}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余{{item.sell_count}}件</span>
                </p>
            </div>
        </div>
        <!-- //加载更多按钮应该添加@click="getMore"方法监听。 -->
         <mt-button type="danger" size="large" onclick="#">加载更多</mt-button>
    </div>
</template>


<script>
export default {
    data(){
        return{
            goodsLists: [
                {
                    id:1,
                    title:"波西米亚性感娃娃",
                    img_src:require("../../images/goods1-1.jpg"),
                    price_now:990,
                    price_old:1333,
                    sell_count:100,
            
                },
                    {
                    id:2,    
                    title:"喷血热辣娃娃",
                    img_src:require("../../images/goods1-2.jpg"),
                    price_now:290,
                    price_old:933,
                    sell_count:50,
                
                },

                    {
                    id:3,
                    title:"小清新娃娃",
                    img_src:require("../../images/goods1-3.jpg"),
                    price_now:440,
                    price_old:733,
                    sell_count:300,
                
                },

                    {
                    id:4,    
                    title:"明星景甜同款娃娃",
                    img_src:require("../../images/goods1-4.jpg"),
                    price_now:1110,
                    price_old:1433,
                    sell_count:220,
                
                },

                    {
                    id:5,     
                    title:"让你欲罢不能的娃娃",
                    img_src:require("../../images/goods1-5.jpg"),
                    price_now:8890,
                    price_old:15333,
                    sell_count:100,
                
                },

                    {
                    id:6,
                    title:"月草月紧的娃娃",
                    img_src:require("../../images/goods1-6.jpg"),
                    price_now:3990,
                    price_old:6333,
                    sell_count:300,
                
                },

                    {
                    id:7,    
                    title:"自带震动高潮迭起娃娃",
                    img_src:require("../../images/goods1-7.jpg"),
                    price_now:8990,
                    price_old:22243,
                    sell_count:500,
                
                },
                    {
                    id:8,    
                    title:"鸡巴硬邦邦娃娃",
                    img_src:require("../../images/goods1-8.jpg"),
                    price_now:66031,
                    price_old:66633,
                    sell_count:40,
                
                },
            ],
            // pageindex:1
        }
    },

// created(){
//     this.getGoodslist();
// },

    methods: {
        // getGoodslist(){
        //     this.$http.get("api/getgoods?pageindex=" + this.pageindex)
        //     .then(result => {
        //         if (result.body.status === 0){
        //             this.goodsLists = this.goodslist.concat(result.body.message)
        //         }
        //     });
        // },

        // getMore(){
        //     this.pageindex++;
        //     this.getGoodslist();
        // },
 // 使用JS的形式进行路由导航

      // 注意： 一定要区分 this.$route 和 this.$router 这两个对象，
      // 其中： this.$route 是路由【参数对象】，所有路由中的参数， params, query 都属于它
      // 其中： this.$router 是一个路由【导航对象】，用它 可以方便的 使用 JS 代码，实现路由的 前进、后退、 跳转到新的 URL 地址

        goDetail(id){
            
                  // 1. 最简单的
                 // this.$router.push("/home/goodsinfo/" + id);
                 // 2. 传递对象
                this.$router.push({ path: "/home/goodsinfo/" + id });
                // 3. 传递命名的路由
            // this.$router.push({name:"goodsinfo",param:{id}});
        }
    },
}
</script>



<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding:7px;
    justify-content:space-between;

    .goods-item{
        background-color: white;
        width:49%;
       
        border:1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        margin:4px 0;
        padding:2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 250px;
   
            img{
            width:100%;
            height:70%;
            }

        .title{
            font-size: 14px;
        }

        .info{
            background-color: #eee;
            p{
                margin:0;
                padding:5px;
            }
            .price{
                .now{
                    color:red;
                    font-weight: bold;
                    font-size: 16px;

                }

                .old{
                    text-decoration: line-through;
                    font-size: 12px;
                    margin-left: 10px;
                }
            }

            .sell{
                display: flex;
                justify-content: space-between;
                font-size: 13px;
            }

        }
    
    }
}

</style>
